﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Configuration;
using LeadVinaglue.Models.ViewPages;
using LeadVinaglue.Models;

namespace LeadVinaglue.Areas.Management.Controllers
{
    public class DocumentTypeListController : Controller
    {
        // Create an instance of user manage
        LeadVinaglue.Repository.DocumentTypeManagementRepository repository = new LeadVinaglue.Repository.DocumentTypeManagementRepository();
        public static string PartnerImagesURL = ConfigurationManager.AppSettings["PartnerImagesURL"].ToString();
        //
        // GET: /Management/StateList/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Index()
        {
            DocumentTypeManagementModel model = new DocumentTypeManagementModel();
            model = repository.GetModel(Helpers.Constant.HOME, "SuperAdministrator");

            return View(model);
        }

        //
        // GET: /Management/LanguageList/Edit/id
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Add()
        {
            DocumentTypeManagementModel model = new DocumentTypeManagementModel();
            model = repository.GetModelAdd(Helpers.Constant.HOME, "SuperAdministrator");

            return View(model);
        }

        [HttpPost]
        [ValidateInput(false)]
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Add(FormCollection form)
        {
            DocumentType model = new DocumentType();

            model.Title = form["Title"].ToString();
            model.Visible = (form["Visible"] != null && form["Visible"].ToString() == "on");

            repository.Create(model);

            return RedirectToAction("Index", "LanguageList");
        }

        //
        // GET: /Management/LanguageList/Edit/id
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Edit(int id)
        {
            DocumentTypeManagementModel model = new DocumentTypeManagementModel();
            model = repository.GetModelEdit(Helpers.Constant.HOME, "SuperAdministrator", id);
            ViewBag.PartnerId = id;

            return View(model);
        }

        //
        // GET: /Management/PartnerList/Edit/id
        [HttpPost]
        [ValidateInput(false)]
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Edit(int id, FormCollection form)
        {
            DocumentType model = repository.GetSingle(id);

            if (model != null)
            {
                model.Title = form["Title"].ToString();
                model.Visible = (form["Visible"] != null && form["Visible"].ToString() == "on");

                repository.Save(model);
            }

            return RedirectToAction("Index", "LanguageList");
        }

        // Delete Email Item
        [HttpGet]
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Delete(int id)
        {
            repository.Delete(id);

            DocumentTypeManagementModel model = new DocumentTypeManagementModel();
            model = repository.GetModelDelete(Helpers.Constant.HOME, "SuperAdministrator");

            return Json(model, JsonRequestBehavior.AllowGet);
        }
    }
}
